package com.example.mushroom.controller;

import com.example.mushroom.entity.Log;
import com.example.mushroom.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/logs")
public class LogController {

    @Autowired
    private LogService logService;

    @PostMapping
    public int insertLog(@RequestBody Log log) {
        return logService.insertLog(log);
    }

    @GetMapping("/{id}")
    public Log selectLogById(@PathVariable Integer id) {
        return logService.selectLogById(id);
    }

    @GetMapping
    public List<Log> selectAllLogs() {
        return logService.selectAllLogs();
    }

    @PutMapping
    public int updateLog(@RequestBody Log log) {
        return logService.updateLog(log);
    }

    @DeleteMapping("/{id}")
    public int deleteLogById(@PathVariable Integer id) {
        return logService.deleteLogById(id);
    }

    @GetMapping("/page")
    public List<Log> selectLogsByPage(@RequestParam int offset, @RequestParam int limit) {
        return logService.selectLogsByPage(offset, limit);
    }
}